package com.imachen.ymcc.controller;

import com.imachen.ymcc.doc.CourseDoc;
import com.imachen.ymcc.dto.CourseEsDto;
import com.imachen.ymcc.result.JSONResult;
import com.imachen.ymcc.result.PageList;
import com.imachen.ymcc.service.ICourseEsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/course")
public class CourseEsController {


    @Autowired
    private ICourseEsService courseEsService;

    @PreAuthorize("hasAuthority('es:saveCourse')")
    @RequestMapping(value="/saveCourseEs",method= RequestMethod.POST)
    public JSONResult saveCourseEs(@RequestBody CourseDoc courseDoc){
        courseEsService.saveCourseEs(courseDoc);
        return JSONResult.success();
    }

    @RequestMapping(value="/deleteCourseEs/{id}",method= RequestMethod.POST)
    public JSONResult deleteCourseEs(@PathVariable("id") Long id){
        courseEsService.deleteCourseEs(id);
        return JSONResult.success();
    }

    /**
     * @description: es课程搜索
     * @author: AChen
     * @date: 2022/10/14 0014 : 17:46
     * @param:
     * @return:
     */
    @RequestMapping(value="/search",method= RequestMethod.POST)
    public JSONResult search(@RequestBody CourseEsDto courseEsDto){
        PageList<CourseDoc> pageList = courseEsService.search(courseEsDto);
        return JSONResult.success(pageList);
    }


}
